package com.kingdee.eas.custom.hostelmgr.basedata.app;

import org.apache.log4j.Logger;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.custom.hostelmgr.basedata.HostelBasicInfo;
import com.kingdee.eas.custom.hostelmgr.basedata.TypeEnum;
import com.kingdee.eas.custom.hostelmgr.beddistribution.BedDistributionFactory;
import com.kingdee.eas.custom.hostelmgr.beddistribution.BedDistributionInfo;
import com.kingdee.eas.framework.CoreBaseCollection;
import com.kingdee.eas.framework.CoreBaseInfo;
import com.kingdee.eas.framework.DataBaseInfo;

public class HostelBasicControllerBean extends
		AbstractHostelBasicControllerBean {
	private static Logger logger = Logger
			.getLogger("com.kingdee.eas.custom.hostelmgr.basedata.app.HostelBasicControllerBean");

	protected IObjectPK _addnew(Context ctx, IObjectValue model)
			throws BOSException, EASBizException {
		HostelBasicInfo basicInfo = (HostelBasicInfo) model;
		IObjectPK pk = super._addnew(ctx, model);
		if (basicInfo.getType().equals(TypeEnum.BED)) {
			CoreBaseCollection bedCollection = new CoreBaseCollection();
			BedDistributionInfo bedDest = new BedDistributionInfo();
			bedDest.setBed(basicInfo);
			bedDest.setBed(basicInfo);
			bedCollection.add(bedDest);

			BedDistributionFactory.getLocalInstance(ctx).addnew(bedCollection);
		}
		return pk;
	}

	public IObjectPK submit(Context ctx, CoreBaseInfo model)
			throws BOSException, EASBizException {
		this.checkNumberDup(ctx, (DataBaseInfo)model);
		IObjectPK pk = super.submit(ctx, model);
		return pk;
	}
}